﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAccess.DepositSavingCurrency;
using System.Data;
using FOModels.DepositSavingCurrency;
using System.Net;
namespace Bussiness.DepositSavingCurrency
{
    public class DepositSavingCurrencyBLL
    {
        private DepositSavingCurrencyDAL dal;
        public DepositSavingCurrencyBLL()
        {
            dal = new DepositSavingCurrencyDAL();
        }
        public int UpdateStatus(SavingCurrencyApplyModels card)
        {
            if (dal.UpdateStatus(card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteSavingCurrencyApply(int SavingDepositApplyID)
        {
            if (dal.DeleteSavingCurrencyApply(SavingDepositApplyID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int SavingCurrencyApply(int DepositSavingID, SavingCurrencyApplyModels card)
        {
            if (dal.SavingCurrencyApply(DepositSavingID, card) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public SavingCurrencyApplyModels getcontractbyid(int cardapplyid)
        {

            SavingCurrencyApplyModels fur = new SavingCurrencyApplyModels();
            DataTable tb = dal.getcontractbyid(cardapplyid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new SavingCurrencyApplyModels();
                    fur.SavingCurrencyApplyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.CompanyImg = row[20].ToString();
                    fur.CompanyName = row[27].ToString();
                    fur.StatusName = row[18].ToString();
                }
            }
            return fur;
        }
        public List<SavingCurrencyApplyModels> getcontract()
        {
            List<SavingCurrencyApplyModels> list = new List<SavingCurrencyApplyModels>();
            SavingCurrencyApplyModels fur;
            DataTable tb = dal.getcontract();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new SavingCurrencyApplyModels();
                    fur.SavingCurrencyApplyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.CompanyImg = row[20].ToString();
                    fur.CompanyName = row[27].ToString();
                    fur.StatusName = row[18].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<SavingCurrencyApplyModels> getcontractbystatus(int statusid)
        {
            List<SavingCurrencyApplyModels> list = new List<SavingCurrencyApplyModels>();
            SavingCurrencyApplyModels fur;
            DataTable tb = dal.getcontractbystatus(statusid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new SavingCurrencyApplyModels();
                    fur.SavingCurrencyApplyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyID = int.Parse(row[1].ToString());
                    fur.CustomerName = row[2].ToString();
                    fur.CustomerEmail = row[3].ToString();
                    fur.CustomerPhone = row[4].ToString();
                    fur.CustomerIncome = row[5].ToString();
                    fur.CustomerDOB = row[6].ToString();
                    fur.StatusID = int.Parse(row[7].ToString());
                    fur.AppDate = row[8].ToString();
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.CompanyImg = row[20].ToString();
                    fur.CompanyName = row[27].ToString();
                    fur.StatusName = row[18].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public DepositSavingCurrencyModels getTOP1()
        {
            DepositSavingCurrencyModels fur = new DepositSavingCurrencyModels();
            DataTable tb = dal.getTOP1();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                }
            }
            return fur;
        }
        public List<CurrencyCateModels> getCurrencyCate(int langid)
        {
            List<CurrencyCateModels> list = new List<CurrencyCateModels>();
            CurrencyCateModels fur;
            DataTable tb = dal.getCurrencyCate(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new CurrencyCateModels();
                    fur.CurrencyCateID = int.Parse(row[0].ToString());
                    fur.CurrencyCateName = row[5].ToString();
                    fur.CurrencyCateSymbol = row[2].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingCurrencyModels> getDepositSavingCurrencyDefault(int langid)
        {
            List<DepositSavingCurrencyModels> list = new List<DepositSavingCurrencyModels>();
            DepositSavingCurrencyModels fur;
            DataTable tb = dal.getDepositSavingCurrencyDefault(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[23].ToString();
                    fur.CompanyImg = row[16].ToString();
                    fur.InterestVND = float.Parse(row[27].ToString());
                    fur.InterestEUR = float.Parse(row[28].ToString());
                    fur.InterestUSD = float.Parse(row[29].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingCurrencyModels> getDepositSavingCurrency(int cateid, int currencyid, int balance, int month,int langid)
        {
            List<DepositSavingCurrencyModels> list = new List<DepositSavingCurrencyModels>();
            DepositSavingCurrencyModels fur;
            DataTable tb = dal.getDepositSavingCurrencyAll(cateid, currencyid, balance, month,langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[23].ToString();
                    fur.CompanyImg = row[16].ToString();
                    fur.InterestVND = float.Parse(row[27].ToString());
                    fur.InterestEUR = float.Parse(row[28].ToString());
                    fur.InterestUSD = float.Parse(row[29].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingCurrencyModels> getDepositSavingCurrencyByProvider(int cateid, int currencyid, int balance, int month, int CompanyID,int langid)
        {
            List<DepositSavingCurrencyModels> list = new List<DepositSavingCurrencyModels>();
            DepositSavingCurrencyModels fur;
            DataTable tb = dal.getDepositSavingCurrencyByProvider(cateid, currencyid, balance, month, CompanyID,langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[23].ToString();
                    fur.CompanyImg = row[16].ToString();
                    fur.InterestVND = float.Parse(row[27].ToString());
                    fur.InterestEUR = float.Parse(row[28].ToString());
                    fur.InterestUSD = float.Parse(row[29].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<DepositSavingCurrencyModels> getdepositsavingrelati(int CompanyID, int DepositSavingID,int langid)
        {
            List<DepositSavingCurrencyModels> list = new List<DepositSavingCurrencyModels>();
            DepositSavingCurrencyModels fur;
            DataTable tb = dal.getdepositsavingrelati(CompanyID, DepositSavingID,langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[23].ToString();
                    fur.CompanyImg = row[16].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public DepositSavingCurrencyModels getDepositSavingCurrencyByID(int SavingCurrencyID, int langid)
        {
            DepositSavingCurrencyModels fur = new DepositSavingCurrencyModels();
            DataTable tb = dal.getDepositSavingCurrencyByID(SavingCurrencyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[23].ToString();
                    fur.CompanyImg = row[16].ToString();

                }
            }
            return fur;
        }
        public DepositSavingCurrencyModels getDepositSavingCurrencyByIDManager(int SavingCurrencyID, int langid)
        {
            DepositSavingCurrencyModels fur = new DepositSavingCurrencyModels();
            DataTable tb = dal.getDepositSavingCurrencyByIDManager(SavingCurrencyID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[23].ToString();
                    fur.CompanyImg = row[16].ToString();

                }
            }
            return fur;
        }
        public List<DepositSavingCurrencyModels> getall(int langid)
        {
            List<DepositSavingCurrencyModels> list = new List<DepositSavingCurrencyModels>();
            DepositSavingCurrencyModels fur;
            DataTable tb = dal.getall(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[29].ToString();
                    fur.CompanyImg = row[16].ToString();
                    fur.CurrencyCateName = row[26].ToString();
                    fur.CurrencyCateSymbol = row[23].ToString();
                    fur.FlagImage = row[34].ToString();

                    list.Add(fur);
                }
            }
            return list;
        }
        public int UpdateDepositSavingCurrency(DepositSavingCurrencyModels models, int langid)
        {
            if (dal.UpdateDepositSavingCurrency(models) > 0 && dal.UpdateDepositSavingCurrencyLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertDepositSavingCurrency(DepositSavingCurrencyModels models)
        {
            if (dal.InsertDepositSavingCurrency(models) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertDepositSavingCurrencyLang(DepositSavingCurrencyModels models, int langid)
        {
            if (dal.InsertDepositSavingCurrencyLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteDepositSavingCurrency(int DepositSavingCurrencyID)
        {
            if (dal.DeleteDepositSavingCurrencyLang(DepositSavingCurrencyID) > 0 && dal.DeleteDepositSavingCurrency(DepositSavingCurrencyID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public List<DepositSavingCurrencyModels> getDepositSavingCurrencyByProviderDefault(int CompanyID,int langid)
        {
            List<DepositSavingCurrencyModels> list = new List<DepositSavingCurrencyModels>();
            DepositSavingCurrencyModels fur;
            DataTable tb = dal.getDepositSavingCurrencyByProviderDefault(CompanyID,langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new DepositSavingCurrencyModels();
                    fur.SavingCurrencyID = int.Parse(row[0].ToString());
                    fur.SavingCurrencyName = row[10].ToString();
                    fur.MinimumBalance = String.Format("{0:0,0}", double.Parse(row[2].ToString())).Replace(',', '.');
                    fur.MaximumBalance = String.Format("{0:0,0}", double.Parse(row[3].ToString())).Replace(',', '.');
                    fur.CompanyID = int.Parse(row[4].ToString());
                    fur.SavingDepositCategoryID = int.Parse(row[5].ToString());
                    fur.CurrencyCateID = int.Parse(row[6].ToString());
                    fur.Description = WebUtility.HtmlDecode(row[11].ToString());
                    fur.Benefit = WebUtility.HtmlDecode(row[12].ToString());
                    fur.FeeContent = WebUtility.HtmlDecode(row[13].ToString());
                    fur.MoreInfo = WebUtility.HtmlDecode(row[14].ToString());
                    fur.Display = bool.Parse(row[7].ToString());
                    fur.CompanyName = row[23].ToString();
                    fur.CompanyImg = row[16].ToString();
                    fur.InterestVND = float.Parse(row[27].ToString());
                    fur.InterestEUR = float.Parse(row[28].ToString());
                    fur.InterestUSD = float.Parse(row[29].ToString());
                    list.Add(fur);
                }
            }
            return list;
        }


    }
}
